import { computed } from 'vue';
import { store } from '@/store';

// 获取所选科室文章
export const useDeptArticle = () => {
  const deptArticleInfo = computed(() => store.state.currentDeptArticle);
  const isDeptEmpty = Object.keys(deptArticleInfo.value).length;
  function setDeptArticle(dept) {
    store.commit('setDeptArticle', dept);
  }

  return { deptArticleInfo, setDeptArticle, isDeptEmpty };
};

// 获取 userInfo
export const useUserInfo = () => {
  const userInfo = computed(() => store.state.global.userInfo);
  return userInfo;
};

// 获取当前所在科室
export const useCurrentDeptInfo = () => {
  const currentDeptInfo = computed(() => store.state.global.currentDeptInfo);
  return currentDeptInfo;
};

// 浏览记录
export const useRecords = () => {
  let startRecord = (articleId) => {
    store.commit('setRecords', articleId);
  };

  return { startRecord };
};

export const useIsRecords = (articleId) => {
  return store.state.global.records.includes(articleId) || false;
};
